package cc.hexie.fish.dao;

import cc.hexie.fish.mapper.AccountMapper;
import cc.hexie.fish.pojo.AccountBean;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.util.List;

@Repository
public class AccountDaoImpl implements AccountDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

//    @PostConstruct
//    private void initialize() {
//        setDataSource(dataSource);
//    }

    @Override
    public List<AccountBean> findAll() {
        List<AccountBean> accountBeanList = jdbcTemplate.query("select * from account", new AccountMapper());
        return accountBeanList;
    }

    @Override
    public AccountBean findById(int id) {
        AccountBean bean = jdbcTemplate.queryForObject("select * from account where id = ?",new AccountMapper(), id);
        return bean;
    }

    @Override
    public void updateMoney(AccountBean accountBean) {
        jdbcTemplate.update("update account set money = ? where id = ?", accountBean.getMoney(), accountBean.getId());
    }
}
